package com.ruoyi.bizsys.service.impl;

import java.util.List;
import java.util.Arrays;

import com.ruoyi.common.utils.DateUtils;
import org.springframework.stereotype.Service;
import com.ruoyi.bizsys.mapper.CreditFlagMapper;
import com.ruoyi.bizsys.domain.CreditFlag;
import com.ruoyi.bizsys.service.ICreditFlagService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;


/**
 * 授权标识Service业务层处理
 *
 * @author african-loan
 * @date 2021-12-30
 */
@Service
public class CreditFlagServiceImpl extends ServiceImpl<CreditFlagMapper, CreditFlag> implements ICreditFlagService {

    /**
     * 查询授权标识
     *
     * @param id 授权标识ID
     * @return 授权标识
     */
    @Override
    public CreditFlag selectCreditFlagById(Long id) {
        return this.getById(id);
    }

    /**
     * 查询授权标识列表
     *
     * @param creditFlag 授权标识
     * @return 授权标识
     */
    @Override
    public List<CreditFlag> selectCreditFlagList(CreditFlag creditFlag) {
        return this.list(new QueryWrapper<>(creditFlag).last("order by id desc"));
    }

    /**
     * 新增授权标识
     *
     * @param creditFlag 授权标识
     * @return 结果
     */
    @Override
    public int insertCreditFlag(CreditFlag creditFlag) {
        creditFlag.setCreateTime(DateUtils.getNowDate());
        return baseMapper.insert(creditFlag);
    }

    /**
     * 修改授权标识
     *
     * @param creditFlag 授权标识
     * @return 结果
     */
    @Override
    public int updateCreditFlag(CreditFlag creditFlag) {
        creditFlag.setUpdateTime(DateUtils.getNowDate());
        return baseMapper.updateById(creditFlag);
    }

    /**
     * 批量删除授权标识
     *
     * @param ids 需要删除的授权标识ID
     * @return 结果
     */
    @Override
    public int deleteCreditFlagByIds(Long[] ids) {
        return baseMapper.deleteBatchIds(Arrays.asList(ids));
    }

    /**
     * 删除授权标识信息
     *
     * @param id 授权标识ID
     * @return 结果
     */
    @Override
    public int deleteCreditFlagById(Long id) {
        return baseMapper.deleteById(id);
    }

    @Override
    public CreditFlag getOne(String serialNo, String type) {
        QueryWrapper<CreditFlag> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("serial_no",serialNo).eq("type",type);
        queryWrapper.last("order by id desc limit 1");
        return getOne(queryWrapper);
    }

    @Override
    public List<CreditFlag> getApprovalFlags(String custNo) {
        return baseMapper.getApprovalFlags(custNo);
    }

}
